package org.gourpg.entity.project;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.*;
import java.util.Calendar;
import java.util.Objects;

/**
 * 项目基础信息实体
 */
@Entity
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Table(name = "project_detail")
public class ProjectDetail {
    /**
     * 项目编号，主键
     */
    @Id
    @NonVisual
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long projectId;

    @Validate("required")
    /**
     * 项目名称
     */
    private String projectName;

    /**
     * 项目类型（自研项目、外部项目、人力项目）字典 PROJECT_TYPE
     */
    private String projectType;

    /**
     * 项目状态（待启动、进行中、已结束、终止）字典 PROJECT_STATUS
     */
    private String projectStatus;

    /**
     * 项目说明
     */
    private String projectRemark;

    /**
     * 启动时间
     */
    private Calendar projectStartTime;

    /**
     * 结束时间
     */
    private Calendar projectEndTime;

    /**
     * 项目负责人
     */
    private Integer projectPersonId;

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        ProjectDetail that = (ProjectDetail) o;
        return getProjectId() != null && Objects.equals(getProjectId(), that.getProjectId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
